import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/home',
    component: Layout,
    redirect: '/home/index',
    meta: { title: '首页' },
    children: [
      {
        path: 'index',
        name: 'homeIndex',
        component: () => import('@/views/home/index'),
        meta: { title: '首页'}
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/banner',
    meta: { title: '基础数据',  },
    children: [
      {
        path: 'banner',
        name: 'banner',
        component: () => import('@/views/banner/index'),
        meta: { title: '轮播图',  }
      },
      {
        path: 'gallery',
        name: 'gallery',
        component: () => import('@/views/gallery/index'),
        meta: { title: '相册',  }
      },
      {
        path: 'ship',
        name: 'ship',
        component: () => import('@/views/ship/index'),
        meta: { title: '出海项目',  }
      },
      {
        path: 'shipCycle',
        name: 'shipCycle',
        component: () => import('@/views/shipCycle/index'),
        meta: { title: '出海排期',  }
      },
      // {
      //   path: 'coupon',
      //   name: 'coupon',
      //   component: () => import('@/views/coupon/index'),
      //   meta: { title: '优惠券',  }
      // },
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/user/index'),
        meta: { title: '注册用户',  }
      },
      {
        path: 'contact',
        name: 'contact',
        component: () => import('@/views/contact/index'),
        meta: { title: '反馈留言',  }
      }
    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: '/order',
    meta: { title: '订单管理',  },
    children: [
      {
        path: 'order-retail',
        name: 'orderRetail',
        component: () => import('@/views/order/retail'),
        meta: { title: '散客单',  }
      },
      {
        path: 'order-detail',
        name: 'orderDetail',
        component: () => import('@/views/order/detail'),
        meta: { title: '订单详情',  },
        hidden: true
      },
      {
        path: 'order-company',
        name: 'orderCompany',
        component: () => import('@/views/order/company'),
        meta: { title: '团体单',  },
      },
      // {
      //   path: 'invoice',
      //   name: 'invoice',
      //   component: () => import('@/views/invoice/index'),
      //   meta: { title: '发票管理',  }
      // }
      {
        path: 'order-email',
        name: 'orderEmail',
        component: () => import('@/views/order-email'),
        meta: { title: '订单邮件记录',  }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/api-log',
    meta: { title: '系统管理'},
    children: [
      {
        path: 'api-log',
        name: 'apiLog',
        component: () => import('@/views/api-log/index'),
        meta: { title: 'API访问记录' }
      },
      {
        path: 'email-template',
        name: 'emailTemplate',
        component: () => import('@/views/email-template/index'),
        meta: { title: '邮件模版' }
      },
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
